#include <myheader.h>

/*Usage:  */
int main(int argc, char *argv[])
{

    //打开读端
    int pipe_read_fd = open("1.pipe",O_RDONLY);
    int pipe_write_fd = open("2.pipe",O_WRONLY);
    char buf[50] = {0};
    while(1){
        //从1.pipe接收数据
        memset(buf,0,sizeof(buf));
        int read_pipe = read(pipe_read_fd,buf,sizeof(buf));
        if(read_pipe == 0){
            printf("对方发送结束\n");
            break;
        }
        //打印
        printf("%s\n",buf);


        //进行发送数据
        memset(buf,0,sizeof(buf));
        int read_stdin = read(STDIN_FILENO,buf,sizeof(buf));
        if(read_stdin == 0){
            printf("终止发送\n");
            break;
        }
        //传输到2.pipe
        write(pipe_write_fd,buf,read_stdin);
        
      }
    close(pipe_read_fd);
    close(pipe_write_fd);
    return 0;
}

